/**
 * Created by Freeman on 2016/7/5.
 */
"use strict";

import {GET_COMMENT_LIST_SUCCESS,GET_COMMENT_LIST_FAILURE,ADD_COMMENT_SUCCESS,ADD_REPLY_SUCCESS} from '../types'

const state = {
    items:[],
    isFetching: false
}
const mutations = {
    [GET_COMMENT_LIST_SUCCESS](state,action){
        state.items = action.commentList
    },
    [GET_COMMENT_LIST_FAILURE](state){
        state.isFetching = false
        state.items = []
    },
    [ADD_COMMENT_SUCCESS](state,action){
        state.items.push(action.comment)
    },
    [ADD_REPLY_SUCCESS](state,action){
        state.items = state.items.map(item=>{
            if(item._id === action.cid){
                item.replys = action.replys
            }
            return item
        })
    }
}

export default {
    state,
    mutations
}